home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Memcpy Problem
- Date: Tue, 05 Mar 96 12:28:48 GMT
- Organization: none
- Message-ID: <826028928snz@genesis.demon.co.uk>
- References: <Pine.OSF.3.91.960304161419.15251A-100000@alpha.fdu.edu>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <Pine.OSF.3.91.960304161419.15251A-100000@alpha.fdu.edu>
- rich@alpha.fdu.edu "Mr. Rich Reybok" writes:
-
- >Hi.
- > I'm writing a little program using BC 4.5, and I seem to have run
- >into a bit of difficulty.
- >Here's the code snippet:
- >
- >{
- >char *temp="2592000"
- >long l;
- >char temp2[100];
- >l=atol(temp)
- >memcpy(temp2,(char *)(&l),sizeof(l));
- >XXX(temp2,LONG_TYPE);
- >}
- >
- >where XXX is defined as XXX(void *value,int datatype); XXX casts value
- >as datatype.
-
- If XXX is written sensibly its first argument would be a pointer to the
- variable concerned so you would just call it as:
-
- XXX(&l, LONG_TYPE);
-
- If internally XXX() simply casts its first argument to long then it is
- very poorly written and isn't portable. Your best chance of making it
- works is:
-
- XXX((void *)l, LONG_TYPE);
-
- > This code basically creates a long value out of a char *
- >that it's gets from elsewhere in the program. It should then copy the
- >byte pattern of the long into a char * and send it to XXX. However I get
- >a memory problem and the debugger exits with error 9. I don't know what
- >error 9 was, couldn't find references to it anywhere :-( If I change l
- >to an int and use atoi everything works fine. However I have one value
- >that will always be a long so I need a solution. Changing XXX is
- >impossible, it is in an SDK I'm using. Any suggestions? Am I
- >overlooking something between the long and int data types?
-
- I think you need to look more carefully at how XXX() is defined. There's
- not a lot more that can be said without knowing more about it.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-